package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.StAcceptanceReport;
import com.ruoyi.system.api.service.IStAcceptanceReportService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 安装验收报告
 *
 * @ClassName AcceptanceReportController.java
 * @date 2020/3/9 8:41 上午
 * @author yzg
 */
@Api(tags="安装验收报告")
@RestController
@RequestMapping("/api/cc/acceptance/report/")
public class AcceptanceReportController extends BaseController {

    @Autowired
    private IStAcceptanceReportService acceptanceReportService;

    private static final Logger log = LoggerFactory.getLogger(AcceptanceReportController.class);

    /**
     *  添加验收报告
     *
     * @param acceptanceReport
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020-03-02 13:56
     */
    @Log(title = "添加验收报告", businessType = BusinessType.INSERT)
    @PostMapping("addAcceptanceReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "添加验收报告", httpMethod = "POST", notes = "添加验收报告")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> addAcceptanceReport(@RequestBody StAcceptanceReport acceptanceReport) {
        try {
            return acceptanceReportService.addAcceptanceReport(acceptanceReport);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  修改验收报告
     *
     * @param acceptanceReport
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/5 10:23 上午
     */
    @Log(title = "修改验收报告", businessType = BusinessType.UPDATE)
    @PostMapping("updateAcceptanceReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "修改验收报告", httpMethod = "POST", notes = "修改验收报告")
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> updateAcceptanceReport(@RequestBody StAcceptanceReport acceptanceReport) {
        try {
            return acceptanceReportService.updateAcceptanceReport(acceptanceReport);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  提交验收报告
     *
     * @param id 提交验收报告主键ID
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/7 10:29 上午
     */
    @RepeatSubmit
    @Log(title = "提交验收报告", businessType = BusinessType.UPDATE)
    @GetMapping("acceptanceReportSubmit")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "提交验收报告", httpMethod = "GET", notes = "提交验收报告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "验收报告主键ID", name = "id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(value = "提交的工程师id", name = "enginnerId", required = true, dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> acceptanceReportSubmit(@RequestParam Long id, @RequestParam Long enginnerId){
        try {
            return acceptanceReportService.acceptanceReportSubmit(id, enginnerId);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     *  查看验收报告
     *
     * @param id 验收报告主键ID
     * @return com.ruoyi.system.api.ResponseWithData<?>
     * @author yzg
     * @date 2020/3/5 9:31 上午
     */
    @GetMapping("detailAcceptanceReport")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查看验收报告", httpMethod = "GET", notes = "查看验收报告")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "验收报告主键ID", name = "id", required = true, dataType = "int", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> detailAcceptanceReport(@RequestParam(value = "id") Long id) {
        try {
            return acceptanceReportService.detailAcceptanceReport(id);
        } catch (Exception e) {
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

}
